package com.tanger.permission.mapper.role;

import com.tanger.permission.entity.vo.UserRoleVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 数据持久接口层
 */
@Mapper
public interface UserRoleManualMapper{

	/**
	 * 查询用户角色集合
	 * @param userId 参数
	 * @return
	 */
	@Select("SELECT " +
				"ur.id, ur.user_id AS userId, ur.role_id AS roleId,br.role_code AS roleCode," +
				"br.role_name AS roleName,br.is_able AS isAble, br.is_del AS isDel " +
			"FROM brt_base_user_role ur LEFT JOIN brt_base_role br ON ur.role_id = br.id " +
			"WHERE 1=1 AND user_id = #{userId}")
	List<UserRoleVo> queryUserRoleByUserId(@Param("userId") Long userId);

	@Delete({"<script>",
				"DELETE FROM brt_base_user_role WHERE user_id IN" +
					"<foreach collection='userIds' index='index' item='item' separator=',' open='(' close=')'>" +
						"#{item,jdbcType=BIGINT}" +
					"</foreach>",
			"</script>"})
	int deleteUSerRoleByUserId(@Param("userIds") List<Long> userIds);

}
